home *** CD-ROM | disk | FTP | other *** search
/ A.C.E. 3 / ACE CD 3.iso / files / utils / hyperbo2.dms / in.adf / Applications / Calculator.hb (.txt) < prev    next >
Encoding:
HyperBook  |  1991-01-29  |  6.9 KB  |  99 lines

  1. 2/* Adds the symbol that is the initiator's name to the text of the Display
  2.    note.
  3. display = 'Display'()
  4. ckey    = getname(initiator())
  5. if getvar(clear) then do
  6.    if index('0123456789.()', ckey) > 0 then
  7.       call cleartext(display)
  8.    call setvar(clear,0)
  9.    end
  10. call inserttext(display,ckey,-1)
  11.     DoCalcKey
  12. "/* Calculator equals key */
  13. disp = 'Display'()
  14. expr = compress(readnotetext(disp,0,-1),'0a'X)
  15. if expr = '' then do
  16.    call inserttext(disp, '0', 0)
  17.    EXIT
  18.    end
  19. signal on syntax
  20. interpret 'value =' expr
  21. signal off syntax
  22. call cleartext(disp)
  23. call inserttext(disp, value, 0)
  24. call interactive(0)
  25. pt = 'Paper tape'()
  26. it = appenditem(pt, expr, 1)
  27. call setactionmacro(it,'ToDisplay')
  28. it = appenditem(pt, compress(value,'0a'X), 2)
  29. call setactionmacro(it,'ToDisplay')
  30. call listscroll(it)
  31. call setvar(clear,1)
  32. syntax:
  33. call inform("Error")
  34. DoEqualsKey
  35. tx = getitemtext(initiator())
  36. n  = index(tx, ';') - 1
  37. if n > 0 then
  38.    tx = strip(left(tx, n))
  39. call inserttext('Display'(), tx, -1)
  40.     ToDisplay
  41. /* Get a variable's value: val = getvar(name)
  42.    variables are stored as items in an invisible list called "Vars"
  43. it = searchitems('vars'(),arg(1) '=')
  44. tx = getitemtext(it)
  45. return substr(tx, index(tx,'=') + 1)
  46. getvar(name)
  47. /* Set a variable: setvar(name, val)
  48.    variables are stored as items in an invisible List called "Vars"
  49. vl = 'vars'()
  50. if arg() == 1 then
  51.    if length(searchitems(vl,arg(1) '=')) > 0 then
  52.       return 1
  53.    else
  54.       return 0
  55. it = searchitems(vl,arg(1) '=')
  56. if arg(2) = deletevar then do
  57.    call delete(it)
  58.    return 1
  59.    end
  60. if length(it) > 0 then
  61.    call setitemtext(it, arg(1) '=' || arg(2))
  62.    call appenditem(vl, arg(1) '=' || arg(2), 1)
  63. return 1
  64. setvar(name,val)
  65. Button1
  66. call clearlist('Paper tape'())
  67. Clear paper tape
  68. "Frame"
  69. call cleartext('Display'())
  70. "Memory"
  71. gob='Display'(); text=readnotetext(ob,0,-1); call setclip('calculator_memory',left(text,length(text)-1))
  72. MEMORY
  73. "Recall"
  74. <call inserttext('Display'(),getclip('calculator_memory'),-1)
  75. RECALL
  76. Note1
  77. A Simple Calculator
  78. Operate the calculator by clicking on
  79. buttons with the mouse. Formulas are
  80. shown in the display, and are calculated
  81. when you press the "=" key.
  82. The MEMORY button stores the current
  83. display, which can be a number or entire
  84. formula. You can RECALL this number or
  85. formula at any time, appending it to the
  86. calculator display.
  87. The "paper tape" shows the formula and
  88. result of each calculation. You can click
  89. on any item in the paper tape to append
  90. that number or formula to the calculator
  91. display. "Clear paper tape" removes all
  92. items from the paper tape display.
  93. "Vars"
  94. CLEAR =1
  95.     "Display"
  96. "Paper tape"
  97. "Calculator"
  98. diamond.font
  99.